import { defineStore } from 'pinia';
import { OrderProduct } from '@/api/order-api';

const useOrderStore = defineStore('orders', {
  state: () => ({
    orders: [] as OrderProduct[],
  }),

  getters: {
    orderInfo(state): OrderProduct[] {
      return state.orders;
    },
  },

  actions: {
    // 设置整个订单数组
    setOrders(orders: OrderProduct[]) {
      this.orders = orders;
    },

    // 添加单个订单
    addOrder(order: OrderProduct) {
      this.orders.push(order);
    },

    // 重置订单
    resetOrders() {
      this.$reset();
    },
  },
});

export default useOrderStore;
